import request from '@/utils/request'
import { encrypt } from '@/utils/rsaEncrypt'

export function add(data) {
  return request({
    url: 'api/users',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/users',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/users',
    method: 'put',
    data
  })
}

export function editUser(data) {
  return request({
    url: 'api/users/center',
    method: 'put',
    data
  })
}

export function updatePass(user) {
  const data = {
    oldPass: encrypt(user.oldPass),
    newPass: encrypt(user.newPass)
  }
  return request({
    url: 'api/users/updatePass/',
    method: 'post',
    data
  })
}

export function updateEmail(form) {
  const data = {
    password: encrypt(form.pass),
    email: form.email
  }
  return request({
    url: 'api/users/updateEmail/' + form.code,
    method: 'post',
    data
  })
}

// 用户云桌面关联详情
export function userDesktopDetail(params) {
  return request({
    url: 'api/userDesktop/detail',
    method: 'get',
    params
  })
}

// 申请切换云平台
export function userDesktopApply(data) {
  return request({
    url: 'api/userDesktop/apply',
    method: 'post',
    data
  })
}

// 切换云平台
export function userDesktopSwitch(data) {
  return request({
    url: 'api/userDesktop/switch',
    method: 'post',
    data
  })
}

// 绑定企业微信用户
export function usersBinding(params) {
  return request({
    url: 'api/users/binding',
    method: 'post',
    params
  })
}

// 根据ID查找用户
export function usersFindByIdNoCache(params) {
  return request({
    url: 'api/users/findByIdNoCache',
    method: 'get',
    params
  })
}

// 站点列表
export function getSiteList(params) {
  return request({
    url: 'api/site/list',
    method: 'get',
    params
  })
}

// 查询指定项目所属用户列表
export function getProjectUser(params) {
  return request({
    url: 'api/users/project_users',
    method: 'get',
    params
  })
}

// 获取用户列表
export function usersList(data) {
  return request({
    url: 'api/users/findList/',
    method: 'post',
    data
  })
}

// 重置密码
export function resetPass(params) {
  return request({
    url: 'api/users/resetPass',
    method: 'get',
    params
  })
}
// 获取平台用户信息(非admin账号)
export function getAllUser(params) {
  return request({
    url: '/api/public/queryUser',
    method: 'get',
    params
  })
}
// 获取人事变动 云工场·公司下拉列表
export function checkUserDepts(params) {
  return request({
    url: 'api/users/checkUserDepts',
    method: 'get',
    params
  })
}
// 获取人事变动 OA·公司下拉列表
export function checkUserOaDepts(params) {
  return request({
    url: 'api/users/checkUserOaDepts',
    method: 'get',
    params
  })
}
export default { add, edit, del, userDesktopDetail, userDesktopApply, userDesktopSwitch, usersBinding, usersFindByIdNoCache, getSiteList, getProjectUser, usersList, resetPass, getAllUser }

